package week;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-08 22:19
 **/
public class Week4 {

    public static void main(String[] args) {
        Week4 w = new Week4();
        System.out.println(w.coutPairs(new int[]{1, 2, 3, 4, 5}, 2));
        System.out.println(w.coutPairs(new int[]{1, 2, 3, 4}, 5));
    }


    public long coutPairs(int[] nums, int k) {
        int n = nums.length;
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; ++j) {
                if (nums[i] == 0 || nums[j] == 0) {
                    ++ans;
                    continue;
                }

                if (((long) nums[i] * nums[j]) % k == 0) {
                    ++ans;
                }
            }
        }

        return ans;
    }

    public int earliestFullBloom(int[] plantTime, int[] growTime) {
        Integer index[] = new Integer[growTime.length], max = 0;
        for (int i = 0; i < index.length; i++) {
            index[i] = i;
        }
        Arrays.sort(index, (o, p) -> growTime[p] - growTime[o]);
        for (int i = 0, sum = 0; i < index.length; i++) {
            max = Math.max(max, (sum += plantTime[index[i]]) + growTime[index[i]]);
        }
        return max;
    }

}
